import {
    list
} from '../../../../api/article';
const util = require('../../../../utils/util.js')
let app = getApp()
Component({
  properties: {
    info: {
      type: Object,
    }
  },
    lifetimes: {
        attached(){
          if (this.data.info.tagids != null) {
            this.data.tagIds = this.data.info.tagids.split(',')
            for (var i = 0; i < this.data.tagIds.length; i++) {
              this.data.tagIds[i] = parseInt(this.data.tagIds[i])
            }
          }
          this.setData({
            tagIds: this.data.tagIds
          })
            this.initQuestion()
        },
    },
    data: {
        notice:[],
        tagIds: '',
        pageNum: 1,
        pageSize: 10,
    },
    methods: {
        onReachBottom () {
            this.data.pageNum += 1
            this.initQuestion()
        },
        downRefresh () {
            this.data.notice = []
            this.data.pageSize = 10
            this.data.pageNum = 1
            this.initQuestion()
        },
        initQuestion () {
            let params={
                articleType:0,
                mchId: app.globalData.mchId,
                sortField:"orders",
                sortType:'desc',
                pageNum: this.data.pageNum,
                pageSize: this.data.pageSize,
                tagIds: this.data.tagIds
            }
            list(params).then(res => {
                if (res.data.data.length>0) {
                    res.data.data.forEach(item=>{
                      item.thumbnail = util.thumbnail(item.thumbnail,750,375) 

                        this.data.notice.push(item)
                    })
                }
                this.setData({
                    notice:this.data.notice
                })
            })
        },
        detailClick (e) {
            if (this.data.notice==null) {
                return;
            }
            let id = e.currentTarget.dataset.item.id
            wx.navigateTo({
                url:`/pages/member/detail/detail?id=${id}`,
            })
        }
    }
})
